<!DOCTYPE html>
<html>
<head>
    <title>系统设置 - 垃圾分类系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1400px;
            margin: 0 auto;
        }
        
        .header {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 20px 30px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }
        
        .header h1 {
            color: #2d3748;
            font-size: 28px;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 12px;
        }
        
        .header-actions {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
        }
        
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 10px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            text-decoration: none;
            transition: all 0.3s ease;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }
        
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
        }
        
        .btn-danger {
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
            color: white;
        }
        
        .btn-danger:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(239, 68, 68, 0.3);
        }
        
        .btn-success {
            background: linear-gradient(135deg, #10b981 0%, #059669 100%);
            color: white;
        }
        
        .btn-success:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);
        }
        
        .nav-tabs {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 16px;
            padding: 8px;
            margin-bottom: 30px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            display: flex;
            gap: 4px;
            overflow-x: auto;
        }
        
        .nav-tab {
            padding: 12px 24px;
            border-radius: 12px;
            text-decoration: none;
            color: #718096;
            font-weight: 500;
            transition: all 0.3s ease;
            white-space: nowrap;
        }
        
        .nav-tab.active {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
        }
        
        .nav-tab:hover:not(.active) {
            background: rgba(102, 126, 234, 0.1);
            color: #667eea;
        }
        
        .page-title {
            color: white;
            font-size: 32px;
            font-weight: 700;
            margin-bottom: 30px;
            text-align: center;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        .tab-container {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            animation: slideUp 0.6s ease-out;
            margin-bottom: 30px;
        }
        
        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .tab-buttons {
            display: flex;
            gap: 8px;
            margin-bottom: 30px;
            border-bottom: 2px solid #e5e7eb;
            padding-bottom: 16px;
            overflow-x: auto;
        }
        
        .tab-button {
            padding: 12px 24px;
            background: transparent;
            border: none;
            border-radius: 12px;
            cursor: pointer;
            font-weight: 600;
            color: #6b7280;
            transition: all 0.3s ease;
            white-space: nowrap;
        }
        
        .tab-button.active {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
        }
        
        .tab-button:hover:not(.active) {
            background: rgba(102, 126, 234, 0.1);
            color: #667eea;
        }
        
        .tab-content {
            display: none;
        }
        
        .tab-content.active {
            display: block;
            animation: fadeIn 0.3s ease-in;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        
        .tab-content h2 {
            color: #2d3748;
            font-size: 24px;
            font-weight: 700;
            margin-bottom: 24px;
            display: flex;
            align-items: center;
            gap: 12px;
        }
        
        .form-group {
            margin-bottom: 24px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #374151;
            font-size: 14px;
        }
        
        input[type="text"],
        input[type="number"],
        input[type="file"],
        select {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e5e7eb;
            border-radius: 12px;
            font-size: 16px;
            transition: all 0.3s ease;
            background: white;
        }
        
        input[type="text"]:focus,
        input[type="number"]:focus,
        input[type="file"]:focus,
        select:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            transform: translateY(-1px);
        }
        
        .model-card {
            background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
            border-radius: 16px;
            padding: 20px;
            margin-bottom: 16px;
            border: 2px solid #e5e7eb;
            transition: all 0.3s ease;
        }
        
        .model-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
        }
        
        .current-model {
            border-color: #10b981;
            background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
            box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
        }
        
        .model-name {
            font-weight: 700;
            color: #2d3748;
            margin-bottom: 8px;
            font-size: 18px;
        }
        
        .model-info {
            color: #6b7280;
            font-size: 14px;
            line-height: 1.5;
        }
        
        .info-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 20px;
        }
        
        .info-item {
            background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
            padding: 20px;
            border-radius: 16px;
            border: 2px solid #e5e7eb;
            transition: all 0.3s ease;
        }
        
        .info-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
        }
        
        .info-label {
            font-weight: 600;
            color: #374151;
            margin-bottom: 8px;
            font-size: 14px;
        }
        
        .info-value {
            color: #6b7280;
            font-size: 16px;
            font-weight: 500;
        }
        
        .switch {
            position: relative;
            display: inline-block;
            width: 60px;
            height: 34px;
        }
        
        .switch input {
            opacity: 0;
            width: 0;
            height: 0;
        }
        
        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: #cbd5e0;
            transition: 0.4s;
            border-radius: 34px;
        }
        
        .slider:before {
            position: absolute;
            content: "";
            height: 26px;
            width: 26px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: 0.4s;
            border-radius: 50%;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }
        
        input:checked + .slider {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        input:checked + .slider:before {
            transform: translateX(26px);
        }
        
        .danger-zone {
            background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
            border: 2px solid #ef4444;
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(239, 68, 68, 0.1);
            animation: slideUp 0.6s ease-out;
        }
        
        .danger-zone h3 {
            color: #dc2626;
            margin-bottom: 16px;
            font-size: 20px;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .danger-zone p {
            color: #7f1d1d;
            margin-bottom: 20px;
            line-height: 1.6;
        }
        
        @media (max-width: 768px) {
            .header {
                flex-direction: column;
                gap: 16px;
                text-align: center;
            }
            
            .header-actions {
                justify-content: center;
            }
            
            .nav-tabs {
                justify-content: center;
            }
            
            .page-title {
                font-size: 24px;
            }
            
            .tab-buttons {
                justify-content: center;
            }
            
            .info-grid {
                grid-template-columns: 1fr;
            }
            
            .tab-container {
                padding: 20px;
            }
        }
    </style>
    <script>
        function showTab(tabName) {
            // Hide all tab contents
            var contents = document.getElementsByClassName('tab-content');
            for (var i = 0; i < contents.length; i++) {
                contents[i].classList.remove('active');
            }
            
            // Remove active class from all buttons
            var buttons = document.getElementsByClassName('tab-button');
            for (var i = 0; i < buttons.length; i++) {
                buttons[i].classList.remove('active');
            }
            
            // Show selected tab and mark button as active
            document.getElementById(tabName).classList.add('active');
            event.target.classList.add('active');
        }
    </script>
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>⚙️ 系统设置</h1>
            <div class="header-actions">
                <a href="/" class="btn btn-primary">🏠 返回前台</a>
                <a href="/logout" class="btn btn-danger">🚪 注销</a>
            </div>
        </header>
        
        <nav class="nav-tabs">
            <a href="/admin" class="nav-tab">📊 控制面板</a>
            <a href="/admin/users" class="nav-tab">👥 用户管理</a>
            <a href="/admin/knowledge" class="nav-tab">📚 科普管理</a>
            <a href="/admin/forum" class="nav-tab">💬 社区管理</a>
            <a href="/admin/points_shop" class="nav-tab">🛒 积分商城</a>
            <a href="/admin/settings" class="nav-tab active">⚙️ 系统设置</a>
        </nav>
        
        <h1 class="page-title">⚙️ 系统设置</h1>
        
        <div class="tab-container">
            <div class="tab-buttons">
                <button class="tab-button active" onclick="showTab('general')">🔧 常规设置</button>
                <button class="tab-button" onclick="showTab('model')">🤖 模型管理</button>
                <button class="tab-button" onclick="showTab('performance')">⚡ 性能优化</button>
                <button class="tab-button" onclick="showTab('info')">📋 系统信息</button>
            </div>
            
            <div id="general" class="tab-content active">
                <h2>🔧 应用设置</h2>
                <form action="/admin/update_settings" method="post">
                    <div class="form-group">
                        <label for="app_name">📱 应用名称</label>
                        <input type="text" id="app_name" name="app_name" value="垃圾分类系统" placeholder="请输入应用名称">
                    </div>
                    <div class="form-group">
                        <label for="max_file_size">📁 最大文件大小 (MB)</label>
                        <input type="number" id="max_file_size" name="max_file_size" value="16" min="1" max="100" placeholder="请输入最大文件大小">
                    </div>
                    <button type="submit" class="btn btn-success">💾 保存设置</button>
                </form>
            </div>
            
            <div id="model" class="tab-content">
                <h2>🤖 可用模型</h2>
                {% for model in available_models %}
                <div class="model-card {% if model.path == current_model %}current-model{% endif %}">
                    <div class="model-name">{{ model.name }}</div>
                    <div class="model-info">{{ model.info }}</div>
                </div>
                {% endfor %}
                
                <h2>📤 上传新模型</h2>
                <form action="/admin/upload_model" method="post" enctype="multipart/form-data">
                    <div class="form-group">
                        <label for="model_file">📁 模型文件 (.pth)</label>
                        <input type="file" id="model_file" name="model_file" accept=".pth" required>
                    </div>
                    <button type="submit" class="btn btn-success">📤 上传模型</button>
                </form>
                
                <h2>🏋️ 训练新模型</h2>
                <form action="/admin/train_model" method="post">
                    <div class="form-group">
                        <label for="epochs">🔄 训练轮数</label>
                        <input type="number" id="epochs" name="epochs" value="10" min="1" max="100" placeholder="请输入训练轮数">
                    </div>
                    <div class="form-group">
                        <label for="learning_rate">📈 学习率</label>
                        <input type="number" id="learning_rate" name="learning_rate" value="0.001" step="0.0001" min="0.0001" max="0.1" placeholder="请输入学习率">
                    </div>
                    <button type="submit" class="btn btn-success">🚀 开始训练</button>
                </form>
            </div>
            
            <div id="performance" class="tab-content">
                <h2>⚡ 性能优化</h2>
                <form action="/admin/update_performance" method="post">
                    <div class="form-group">
                        <label for="enhanced_model">🚀 使用增强模型</label>
                        <label class="switch">
                            <input type="checkbox" id="enhanced_model" name="enhanced_model" {% if enhanced_model %}checked{% endif %}>
                            <span class="slider"></span>
                        </label>
                    </div>
                    <div class="form-group">
                        <label for="batch_size">📦 批处理大小</label>
                        <input type="number" id="batch_size" name="batch_size" value="32" min="1" max="128" placeholder="请输入批处理大小">
                    </div>
                    <div class="form-group">
                        <label for="num_workers">👷 工作进程数</label>
                        <input type="number" id="num_workers" name="num_workers" value="4" min="0" max="16" placeholder="请输入工作进程数">
                    </div>
                    <button type="submit" class="btn btn-success">💾 保存设置</button>
                </form>
            </div>
            
            <div id="info" class="tab-content">
                <h2>📋 系统信息</h2>
                <div class="info-grid">
                    <div class="info-item">
                        <div class="info-label">🐍 Python 版本</div>
                        <div class="info-value">{{ python_version }}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">🌶️ Flask 版本</div>
                        <div class="info-value">{{ flask_version }}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">🗄️ SQLAlchemy 版本</div>
                        <div class="info-value">{{ sqlalchemy_version }}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">🔥 PyTorch 版本</div>
                        <div class="info-value">{{ torch_version }}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">🚀 CUDA 可用</div>
                        <div class="info-value">{{ 'Yes' if cuda_available else 'No' }}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">🎮 GPU 数量</div>
                        <div class="info-value">{{ gpu_count }}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">💻 当前设备</div>
                        <div class="info-value">{{ current_device }}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">📊 总预测次数</div>
                        <div class="info-value">{{ total_predictions }}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">🗃️ 数据库路径</div>
                        <div class="info-value">{{ database_path }}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">🤖 当前模型</div>
                        <div class="info-value">{{ current_model }}</div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="danger-zone">
            <h3>⚠️ 危险操作</h3>
            <p>以下操作不可撤销，请谨慎操作。</p>
            <form action="/admin/delete_predictions" method="post" onsubmit="return confirm('确定要删除所有预测历史吗？此操作不可撤销！')">
                <button type="submit" class="btn btn-danger">🗑️ 删除所有预测历史</button>
            </form>
        </div>
    </div>
</body>
</html>